﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using DevExpress.Web.ASPxHeadline;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxCallback;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;

public partial class CVView : ICPRelationshipPage
{
    public CVData m_cvData = new CVData();
    
    #region Properties
    public int m_iCVID
    {
        get
        {
            if (!String.IsNullOrEmpty(Request.QueryString["cvid"]))
            {
                return Convert.ToInt32(Request.QueryString["cvid"]);
            }
            else
            {
                return -1;
            }
        }
    }
    #endregion Properties

    #region Event Handlers

    protected override void Page_Load(object sender, EventArgs e)
    {
        m_lsPermittedRoles.Add(ICPUserRole.CAR);
        base.Page_Load(sender, e);

        Page.Title = "ICP Lintasarta: Relationship, Customer Visit - View";
        if (!IsPostBack && !IsCallback)
        {
            InitVisitData();
        }
    }
    protected void cbkView_Callback(object sender, CallbackEventArgs e)
    {
        System.Threading.Thread.Sleep(KGlobal.AJAX_WAIT_TIME);
        e.Result = HandleView(e.Parameter);
    }
    #endregion Event Handlers

    #region Custom Methods
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    protected void InitVisitData()
    {
        Cached.CustomerVisitTable cachedCV = new Cached.CustomerVisitTable();
        DataTable dtVisitData = cachedCV.GetVisitDetailById(m_iCVID, true);
        if (dtVisitData.Rows.Count > 0)
        {
            m_cvData.iCVID = m_iCVID;
            if (dtVisitData.Rows[0]["VISIT_DATETIME"] != DBNull.Value)
            {
                m_cvData.dtmVisitDatetime = Convert.ToDateTime(dtVisitData.Rows[0]["VISIT_DATETIME"]);
            }
            if (dtVisitData.Rows[0]["VISIT_STATUS"] != DBNull.Value)
            {
                m_cvData.sxVisitStatus = dtVisitData.Rows[0]["VISIT_STATUS"].ToString();
            }
            if (dtVisitData.Rows[0]["CREATE_BY_NAME"] != DBNull.Value)
            {
                m_cvData.sxCreateBy = dtVisitData.Rows[0]["CREATE_BY_NAME"].ToString();
            }
            if (dtVisitData.Rows[0]["RESULT"] != DBNull.Value)
            {
                m_cvData.sxResult = dtVisitData.Rows[0]["RESULT"].ToString();
            }
            if (dtVisitData.Rows[0]["FOLLOW_UP"] != DBNull.Value)
            {
                m_cvData.sxFollowUp = dtVisitData.Rows[0]["FOLLOW_UP"].ToString();
            }
            if (dtVisitData.Rows[0]["P_CUSTOMER_EXPECTATION_ID"] != DBNull.Value)
            {
                m_cvData.iP_Customer_Expectation_ID = Convert.ToInt32(dtVisitData.Rows[0]["P_CUSTOMER_EXPECTATION_ID"]);
            }
            if (dtVisitData.Rows[0]["P_VISIT_PURPOSE_ID"] != DBNull.Value)
            {
                m_cvData.iP_Visit_Purpose_ID = Convert.ToInt32(dtVisitData.Rows[0]["P_VISIT_PURPOSE_ID"]);
            }
            if (dtVisitData.Rows[0]["VISIT_PURPOSE"] != DBNull.Value)
            {
                m_cvData.sxVisitPurpose = dtVisitData.Rows[0]["VISIT_PURPOSE"].ToString();
            }
            if (dtVisitData.Rows[0]["CUSTOMER_EXPECTATION"] != DBNull.Value)
            {
                m_cvData.sxCustomerExpectation = dtVisitData.Rows[0]["CUSTOMER_EXPECTATION"].ToString();
            }
            if (dtVisitData.Rows[0]["COMPANY_NAME"] != DBNull.Value)
            {
                m_cvData.sxCompanyName = dtVisitData.Rows[0]["COMPANY_NAME"].ToString();
            }
            if (dtVisitData.Rows[0]["NAME"] != DBNull.Value)
            {
                m_cvData.sxContactPersonName = dtVisitData.Rows[0]["NAME"].ToString();
            }
            if (dtVisitData.Rows[0]["T_FILE_UPLOAD_ID"] != DBNull.Value)
            {
                m_cvData.iFile_Upload_ID = Convert.ToInt32(dtVisitData.Rows[0]["T_FILE_UPLOAD_ID"]);
            }
            if (dtVisitData.Rows[0]["ORIGINAL_FILENAME"] != DBNull.Value)
            {
                m_cvData.sxOriginalFilename = dtVisitData.Rows[0]["ORIGINAL_FILENAME"].ToString();
            }
            if (dtVisitData.Rows[0]["CONTACT_PERSON_ID"] != DBNull.Value)
            {
                m_cvData.iContactPersonID = Convert.ToInt32(dtVisitData.Rows[0]["CONTACT_PERSON_ID"]);
            }
            if (dtVisitData.Rows[0]["NEW_CONTACT_PERSON_ID"] != DBNull.Value)
            {
                m_cvData.iNewContactPersonID = Convert.ToInt32(dtVisitData.Rows[0]["NEW_CONTACT_PERSON_ID"]);
            }
        }
    }
    private string HandleView(string sxParam)
    {
        String[] sxSplitted = sxParam.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);

        String sxOutput = String.Empty;
        int iCPID = -1;
        bool isNewCP = sxSplitted[2].ToString().ToUpper().Equals("Y");
        switch (sxSplitted[0].ToUpper())
        {
            case "SHOW":
                iCPID = Convert.ToInt32(sxSplitted[1]);
                ContactInfoData cpInfoData = new ContactInfoData();
                Cached.ContactPersonTable cachedCP = new Cached.ContactPersonTable();
                cpInfoData = cachedCP.GetContactInfoData(iCPID,isNewCP);
                sxOutput = CVManager.BuildEditor_CPInfoPopUp(iCPID.ToString(), cpInfoData);
                break;
        }

        return sxOutput;
    }
    #endregion Custom Methods
}
